import API from '../../api/request'

export const navList = [
	{
		type: 'article',
		title: '转发赚钱',
		icon: 'money',
		color: '#C30D23'
	},
	{
		type: 'recruit',
		title: '收徒赚钱',
		icon: 'people10geren',
		color: '#CC6699'
	},
	{
		type: 'withdraw',
		title: '我要提现',
		icon: 'tixian1',
		color: '#CC9966'
	},
	{
		type: 'incomeDetail',
		key: 'totalIncome',
		title: '总收入',
		icon: 'zhanghuyue',
		color: '#aaa',
		subTitle: '0.00',
		isAmount: true
	},
	{
		type: 'withdrawRecord',
		key: 'totalWithdrawal',
		title: '累计提现',
		icon: 'money1',
		color: '#CC9999',
		subTitle: '0.00',
		isAmount: true
	},
	{
		type: 'recruitDetail',
		key: 'totalSubUser',
		title: '我的徒弟',
		icon: 'people5geren',
		color: '#336633',
		subTitle: '0'
	},
	{
		type: 'information',
		title: '我的资料',
		icon: 'wode',
		color: '#666'
	},
	{
		type: 'oneInput',
		key: 'parentId',
		title: '输入师傅ID',
		vali: {
			type: 'integer',
			msg: '师傅id不存在'
		},
		icon: 'aixin',
		color: '#993333'
	},
	{
		type: 'guide',
		title: '新手学堂',
		icon: 'question_line',
		color: '#336699'
	}
]

export function addAtrrHandle(list, info = {}) {
	list.map(item => {
		if (item.key === 'parentId' && info.parentId) {
			item.type = ''
			item.title = '已绑定师傅ID'
		}
		let data = info[item.key]
		if (data && item.subTitle) {
			item.subTitle = data
		}
	})

	return list
}

// 用户每天登录奖励
export async function getAwardOneApi () {
	let isaward = await loadAward()
	if (isaward) return 
	let url = '/api/user/loginRewardEverday'
	let res = await API.post(url)
	if (res.code === '200') {
		saveAward()
		return res.data
	}
}

async function loadAward () {
	let award
	try {
		award = await global.storage.load({
			key: 'login.award'
		})
	} catch(e) {
		
	}
	return award
}

async function saveAward () {
	await global.storage.save({
		key: 'login.award',
		data: true
	})
}